<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" value="按钮1">
    <input type="text" value="按钮2">
    <input type="text" value="按钮3">
    <script>
        /*
        
        var a = 13
        if (true) {
            let a = 10
            console.log(a)
        }
        console.log(a)

        */
        var btn = document.getElementsByTagName('input')
        for (var i = 0; i < 3; i++) {
            (function (i) {
                btn[i].onclick = function () {
                    console.log(i)
                }
            })(i)
        }
    </script>
</body>

</html>